package com.huawei.appgallery.search.ui.widget;

import android.app.Activity;
import android.content.Context;
import android.os.Build.VERSION;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import androidx.appcompat.widget.SearchView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.hwid.core.constants.HwAccountConstants;
import huawei.widget.HwButton;
import huawei.widget.HwSearchView;
import o.cfw;
import o.cuv.a;
import o.cuv.e;
import o.cuv.f;
import o.cux;
import o.dgm;
import o.dgu;
import o.djf;
import o.dof;
import o.dyk;
import o.epv;
import o.evc;

public class NormalSearchView extends LinearLayout implements OnTouchListener {
    private EditText ʻ;
    private String ʼ;
    private View ʽ;
    private HwButton ˊ;
    private boolean ˊॱ;
    private HwSearchView ˋ;
    private Context ˎ;
    private MaxWidthLinearLayout ˏ;
    private boolean ˏॱ;
    private String ͺ;
    private b ॱ;
    private String ॱˊ;
    private boolean ॱॱ = false;
    private String ᐝ;

    public interface b {
        void ˎ(String str);

        void ˏ(String str, String str2, boolean z, boolean z2, String str3);

        void ͺ();

        void ॱ(String str, String str2, boolean z, boolean z2);

        void ᐝ();
    }

    class c implements OnClickListener {
        final /* synthetic */ NormalSearchView ॱ;

        private c(NormalSearchView normalSearchView) {
            this.ॱ = normalSearchView;
        }

        public void onClick(View view) {
            evc.ˊ(view);
            djf.ॱ(this.ॱ.getContext(), this.ॱ.ʼ, this.ॱ.ᐝ, this.ॱ.ʼ(), this.ॱ.ʻ());
            this.ॱ.ॱ(false);
        }
    }

    public NormalSearchView(Context context) {
        super(context);
        this.ˎ = context;
        ˏ();
    }

    public NormalSearchView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ˎ = context;
        ˏ();
    }

    public NormalSearchView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˎ = context;
        ˏ();
    }

    public String ˊ() {
        return this.ͺ;
    }

    public void setHintValue(String str) {
        this.ͺ = str;
    }

    public String ˋ() {
        return this.ॱˊ;
    }

    public void setHintDetailId(String str) {
        this.ॱˊ = str;
    }

    private void ˏ() {
        View inflate = ((LayoutInflater) this.ˎ.getSystemService("layout_inflater")).inflate(e.ॱˋ, this);
        this.ˋ = (HwSearchView) inflate.findViewById(o.cuv.b.ʽˊ);
        LinearLayout linearLayout = (LinearLayout) this.ˋ.findViewById(o.cuv.b.ʹ);
        if (linearLayout != null) {
            linearLayout.setPadding(this.ˎ.getResources().getDimensionPixelSize(a.ʻ) - this.ˎ.getResources().getDimensionPixelSize(a.ˏ), 0, this.ˎ.getResources().getDimensionPixelSize(a.ॱˊ), 0);
        }
        ImageView imageView = (ImageView) this.ˋ.findViewById(o.cuv.b.ॱॱ);
        if (imageView != null) {
            imageView.setContentDescription(this.ˎ.getResources().getString(f.ʽ));
            imageView.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ NormalSearchView ˊ;

                {
                    this.ˊ = r1;
                }

                public void onClick(View view) {
                    if (this.ˊ.ˎ instanceof Activity) {
                        ((Activity) this.ˊ.ˎ).onBackPressed();
                    }
                }
            });
        }
        this.ˏ = (MaxWidthLinearLayout) inflate.findViewById(o.cuv.b.ʼˊ);
        this.ˊ = (HwButton) inflate.findViewById(o.cuv.b.ʼˋ);
        this.ˋ.ˊ();
        this.ˏ.setMaxWidth(epv.ˋ(this.ˎ, 96), true);
        this.ˊ.setOnClickListener(new c());
        if (VERSION.SDK_INT >= 17 && VERSION.SDK_INT <= 19) {
            View findViewById = this.ˋ.findViewById(o.cuv.b.ʻᐝ);
            if (findViewById != null) {
                findViewById.setBackgroundResource(o.cuv.c.ॱ);
            }
        }
        this.ʻ = (EditText) this.ˋ.findViewById(o.cuv.b.ʻˊ);
        if (this.ʻ != null) {
            this.ʻ.setFilters(new InputFilter[]{new LengthFilter(50)});
            this.ʻ.setOnTouchListener(this);
        }
        this.ʽ = inflate.findViewById(o.cuv.b.ʽˋ);
    }

    public HwSearchView ॱ() {
        return this.ˋ;
    }

    public void setSearchView(HwSearchView hwSearchView) {
        this.ˋ = hwSearchView;
    }

    public void setOnSearchActionBarListener(b bVar) {
        this.ॱ = bVar;
    }

    public void setmIsToResult(boolean z) {
        this.ॱॱ = z;
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (!(view == null || view.getId() != o.cuv.b.ʻˊ || motionEvent.getAction() != 0 || this.ॱ == null || this.ˋ == null || TextUtils.isEmpty(this.ˋ.ˋ()))) {
            boolean z = (this.ʻ == null || this.ʽ == null || this.ʽ.isFocusableInTouchMode()) ? false : true;
            if (z) {
                this.ʻ.setCursorVisible(true);
                this.ʽ.setFocusableInTouchMode(true);
            }
            this.ॱ.ˎ(this.ˋ.ˋ().toString());
        }
        return false;
    }

    public void ˎ() {
        if (this.ˋ == null) {
            cux.ˏ.ˊ("NormalSearchView", "addEventListener: mSearchView is null");
            return;
        }
        if (this.ʻ != null) {
            this.ʻ.setOnEditorActionListener(new OnEditorActionListener(this) {
                final /* synthetic */ NormalSearchView ॱ;

                {
                    this.ॱ = r1;
                }

                public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                    if (3 == i) {
                        this.ॱ.ॱॱ();
                    } else {
                        boolean z;
                        if (keyEvent != null && 66 == keyEvent.getKeyCode() && keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) {
                            z = true;
                        } else {
                            z = false;
                        }
                        if (z) {
                            this.ॱ.ʽ();
                        }
                    }
                    return false;
                }
            });
        } else {
            cux.ˏ.ˊ("NormalSearchView", "addEventListener: mSearchView.getSearchSrcTextView() is null");
        }
        this.ˋ.setOnQueryTextListener(new SearchView.e(this) {
            final /* synthetic */ NormalSearchView ˊ;

            {
                this.ˊ = r1;
            }

            public boolean ˋ(String str) {
                this.ˊ.setmIsToResult(false);
                return false;
            }

            public boolean ॱ(String str) {
                if (this.ˊ.ॱ != null) {
                    boolean z = (this.ˊ.ॱॱ || this.ˊ.ʻ == null || this.ˊ.ʽ == null || this.ˊ.ʽ.isFocusableInTouchMode()) ? false : true;
                    if (z) {
                        this.ˊ.ʻ.setCursorVisible(true);
                        this.ˊ.ʽ.setFocusableInTouchMode(true);
                    }
                    if (dof.ˋ(str)) {
                        this.ˊ.ॱ.ᐝ();
                    } else if (!this.ˊ.ॱॱ) {
                        this.ˊ.ॱ.ˎ(str);
                    }
                }
                return true;
            }
        });
    }

    private void ॱॱ() {
        djf.ˋ(getContext(), this.ʼ, this.ᐝ, ʼ(), ʻ());
        ॱ(false);
    }

    private void ʽ() {
        djf.ˎ(getContext(), this.ʼ, this.ᐝ, ʼ(), ʻ());
        ॱ(true);
    }

    private void ॱ(boolean z) {
        if (this.ˋ != null) {
            String valueOf;
            boolean z2;
            String valueOf2 = String.valueOf(this.ˋ.ˋ());
            if (dof.ॱ(valueOf2)) {
                String string = getResources().getString(f.ॱᐝ);
                valueOf = String.valueOf(this.ˋ.ॱॱ());
                if (!(string.equals(valueOf) || valueOf.equals(ˊ()))) {
                    z2 = true;
                    if (!dof.ˋ(valueOf) && this.ॱ != null) {
                        if (!(!z || this.ʻ == null || this.ʽ == null)) {
                            this.ʻ.setCursorVisible(false);
                            this.ʽ.setFocusableInTouchMode(false);
                        }
                        if (z2) {
                            this.ॱ.ॱ(valueOf, ˋ(), false, false);
                            if ((this.ˎ instanceof Activity) && !TextUtils.isEmpty(ˋ())) {
                                dyk.ॱ(this.ˎ, String.valueOf(this.ˋ.getId()), ˋ());
                                cfw.ˎ(dgu.ˋ("11", ˋ(), dgm.ˎ((Activity) this.ˎ)), null);
                                return;
                            }
                            return;
                        }
                        this.ॱ.ॱ(valueOf.replaceAll("\\s+", HwAccountConstants.BLANK), null, false, false);
                        return;
                    }
                }
            }
            valueOf = valueOf2;
            z2 = false;
            if (!dof.ˋ(valueOf)) {
            }
        }
    }

    public void setTraceId(String str) {
        this.ʼ = str;
    }

    public void setHomePageId(String str) {
        this.ᐝ = str;
    }

    public void setSearchPostOnly(boolean z) {
        this.ˏॱ = z;
    }

    public void setForumSearch(boolean z) {
        this.ˊॱ = z;
    }

    private String ʼ() {
        if (this.ˊॱ) {
            return this.ˏॱ ? "2" : "1";
        } else {
            return "0";
        }
    }

    private String ʻ() {
        return this.ˊॱ ? UserSession.getInstance().getUserId() : null;
    }
}
